package com.jiang.daily.Q3354;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/10/28 10:19
 */
class Solution {
    public int countValidSelections(int[] nums) {
        int left = 0, right = 0;
        int len = nums.length;
        for (int i = len - 1; i >= 0; i--) {
            right += nums[i];
        }
        int res = 0;
        int i = 0;
        for (; i < len; i++) {
            if (nums[i] == 0) {
                if (left == right) res += 2;
                else if (Math.abs(left - right) == 1) res += 1;
            }
            left += nums[i];
            right -= nums[i];
        }
        return res;
    }
}
